
#include "Weapon.h"
#include "Afterburner.h"
#include "../Ship.h"
#include "../Utils/Timer.h"
#include "../World.h"

#include <cassert>



Afterburner::Afterburner(int ammo_count, int lifetime, Ship *pship) :
    WeaponGenerator(ammo_count, lifetime, 1.0f, pship) {

    assert(parent_ship != NULL);
}

Afterburner::~Afterburner(){
}

bool Afterburner::shouldDiscard(void){
    return false;
}

bool Afterburner::fire(void){
    // want to drain below a certain point but
    // cannot activate below a higher point
    if (shouldFire()) {
//    if(parent_ship->getEnergy() > 20.0f){
        //too low a value for drain energy will give infinite boost apparently
        parent_ship->drainEnergy(75.0f * Timer::secondsSinceLastFrame());
        parent_ship->accelerate(2.0f, true);
        return true;
    }

    return false;
}

bool Afterburner::shouldFire(void) {
    if (parent_ship->getEnergy() > 10.0f) {
        if (parent_ship->getEnergy() > 50.0f) {
            time_of_last_fire = 0;
        }
        if (time_of_last_fire) {
            return false;
        } else {
            return true;
        }
    } else {
        time_of_last_fire = 1;
        return false;
    }
}

